package com.shared.controller;

import com.shared.pojo.PAddress;
import com.shared.server.PAddressServer;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class PAddressController {

    @Autowired
    private PAddressServer pAddressServer;

    @GetMapping("/address/{userid}")
    @ResponseBody
    @ApiOperation(value = "根据用户id查询收货地址")
    public List<PAddress> findAddress(@PathVariable("userid") Integer userid) {
        return pAddressServer.findAddressByUserId(userid);
    }

    @GetMapping("/deleteaddress/{id}")
    @ResponseBody
    @ApiOperation(value = "根据id删除收货地址")
    public void deleteAddress(@PathVariable("id") Integer id) {
        System.out.println(id);
        this.pAddressServer.deleteAddress(id);
    }

    @PostMapping("/addAddress")
    @ResponseBody
    @ApiOperation(value = "增加收货地址")
    public void addAddress(@RequestBody PAddress pAddress) {
        pAddress.setUserid(1);
        pAddress.setState(0);
        this.pAddressServer.addAddress(pAddress);
    }
}
